<!-- 营收结算标准 -->
<template>
    <div>
        <div>
            创建时间：
            <el-date-picker
                    v-model="searchTime"
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions">
            </el-date-picker>
            <el-button type="primary" @click="searchDataByTime" id="monitorEnter">查询</el-button>
            <el-button type="primary" @click="newPage('new', false)">新建</el-button>
        </div>
        <el-table
                :data="tableData"
                highlight-current-row
                style="width: 100%;margin-top: 20px;">
            <el-table-column
                    type="index"
                    align="center"
                    label="序号"
                    width="50">
            </el-table-column>
            <el-table-column
                    align="center"
                    property="version"
                    label="版本号">
            </el-table-column>
            <el-table-column
                    align="center"
                    property="extractionRule"
                    label="提取规则">
                <template slot-scope="scope">{{extractCategory[scope.row.extractCategory]}}</template>
            </el-table-column>
            <!--<el-table-column
                    align="center"
                    label="规则时间">
                <template slot-scope="scope">{{ruleEffect[scope.row.ruleEffect]}}</template>
            </el-table-column>-->
            <el-table-column
                    align="center"
                    label="计提节点">
                <template slot-scope="scope">
                    <el-button type="text" @click="viewInterval(scope.row.nodeList)">查看</el-button>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="计提基数">
                <template slot-scope="scope">
                    {{scope.row.nodeList | baseNumFilter}}
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="计提比例">
                <template slot-scope="scope">
                    <el-button type="text" @click="viewInterval(scope.row.nodeList)">
                        <p style="padding: 0;margin: 0;" v-for="(item,index) in scope.row.nodeList" v-if="index < 3">{{item.projectLevelName}}:{{item.calculateProportion}}%</p>
                        <p style="padding: 0;margin: 0;" v-if="scope.row.nodeList.length > 3">...</p>
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    property="createTime"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    property="creatorName"
                    label="创建人">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="详细信息">
                <template slot-scope="scope">
                    <el-button type="text" @click="newPage('view',scope.row)">查看</el-button>
                    <el-button type="text" @click="newPage('edit',scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page.sync="tableConfig.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="tableConfig.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="tableConfig.totalSize">
            </el-pagination>
        </div>

        <!-- 区间范围弹框 -->
        <el-dialog
                title="查看"
                :visible.sync="intervalDialogVisible"
                width="500px">
            <div>
                <el-table
                        :data="scaleTableData"
                        border
                        highlight-current-row
                        style="width: 100%;margin-top: 20px;">
                    <el-table-column
                            property="projectLevelName"
                            align="center"
                            label="开发商">
                    </el-table-column>
                    <el-table-column
                            property="calculateNodeNames"
                            align="center"
                            label="计提节点">
                    </el-table-column>
                    <el-table-column
                            property="extractBaseNum"
                            align="center"
                            label="计提基数">
                        <template slot-scope="scope">{{extractBaseNum[scope.row.extractBaseNum]}}</template>
                    </el-table-column>
                    <el-table-column
                            property="calProportion"
                            align="center"
                            label="计提比例">
                        <template slot-scope="scope">{{scope.row.calculateProportion}}%</template>
                    </el-table-column>
                </el-table>
            </div>

            <span slot="footer">
                <el-button @click="intervalDialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import api from '@/api/apiPath'
    import {extractCategory, ruleEffect, calNode, extractBaseNum} from '../fieldMap'

    export default {
        name: "revenueSettlement",
        title:'营收结算标准',
        data() {
            return {
                searchTime: ["", ""],
                scaleTableData: [],
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                intervalDialogVisible: false,
                tableData: [],
                tableConfig: {
                    pageNum: 1,
                    pageSize: 10,
                    totalSize: 10
                },
                // 列表对应值
                extractCategory,
                ruleEffect,
                calNode,
                extractBaseNum
            }
        },
        created() {
            this.getRevenueStandardList()
        },
        mounted() {

        },
        activated(){
            this.searchDataByTime();
        },
        filters: {
            baseNumFilter(list) {
                let arr = [];
                list.forEach((item) => {
                    if(!arr.includes(extractBaseNum[item.extractBaseNum])){
                        arr.push(extractBaseNum[item.extractBaseNum])
                    }
                });
                return arr.join(';')
            }
        },


        methods: {
            newPage(type, row) {
                let query = {
                    type
                };
                if (row) {
                    query['id'] = row.id;
                    if (row.ruleEffect === 1) {
                        query['dateType'] = 'month'
                    } else {
                        query['dateType'] = 'year'
                    }
                }
                this.$router.push({path: "./revenueSettlementHandle", query: query})
            },
            viewInterval(list) {
                this.intervalDialogVisible = true;
                this.scaleTableData = list;
            },
            searchDataByTime() {
                if (this.searchTime === null) {
                    this.searchTime = ["", ""]
                }
                if (this.searchTime.length) {
                    this.tableConfig.startTime = +new Date(this.searchTime[0])
                    this.tableConfig.endTime = +new Date(this.searchTime[1])
                }
                this.tableConfig.pageNum = 1;
                this.getRevenueStandardList();
            },
            getRevenueStandardList() {
                this.axios.post(api.getRevenueStandardList, {
                    startTime: this.tableConfig.startTime,
                    endTime: this.tableConfig.endTime,
                    pageNum: this.tableConfig.pageNum,
                    pageSize: this.tableConfig.pageSize
                }).then((res) => {
                    this.tableData = res.data.data.list
                    this.tableConfig.totalSize = res.data.data.total;
                })
            },
            handleSizeChange(size) {
                this.tableConfig.pageSize = size
                this.getRevenueStandardList()
            },
            handleCurrentChange(page) {
                this.tableConfig.pageNum = page
                this.getRevenueStandardList()
            },
        },
        components: {},
        computed: {}
    }
</script>

<style scoped>

</style>
